<?php


namespace app\logic;

use think\facade\Db;

class SiteNavHelper
{
    public static function load_site_nav($pid = 0, $checked_ids = []) {


        $list = DataHelper::select('tb_site_nav', [
            'pid' => $pid,
            'status' => 0,
        ], [ 'order_by' => 'idx desc' ]);

        foreach ($list as &$item) {
            if (in_array($item['id'], $checked_ids)) {
                $item['checked'] = true;
            }
        }

        foreach ($list as &$item) {
            $children = self::load_site_nav($item['id']);
            $item['children'] = $children;
        }

        return $list;
    }
}